package com.woniu.gf.pawn.productentityweb.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.gf.pawn.comm.core.domain.ProductEntity;
import com.woniu.gf.pawn.comm.core.domain.ProductEntityAssess;
import com.woniu.gf.pawn.comm.core.domain.ProductEntityIdentify;
import com.woniu.gf.pawn.dto.AssessDto;
import com.woniu.gf.pawn.dto.IdentifyDto;
import com.woniu.gf.pawn.param.AssessParam;
import com.woniu.gf.pawn.param.IdentifyParam;
import com.woniu.gf.pawn.param.PageParam;
import com.woniu.gf.pawn.productentityweb.dao.ProductEntityAssessMapper;
import com.woniu.gf.pawn.productentityweb.dao.ProductEntityIdentifyMapper;
import com.woniu.gf.pawn.productentityweb.dao.ProductEntityMapper;
import com.woniu.gf.pawn.productentityweb.service.IProductEntityAssessService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author TL
 * @since 2020-10-14
 */
@Service
public class ProductEntityAssessServiceImpl extends ServiceImpl<ProductEntityAssessMapper, ProductEntityAssess> implements IProductEntityAssessService {
    @Autowired
    private ProductEntityAssessMapper assessMapper;
    @Autowired
    private ProductEntityMapper entityMapper;

    @Override
    public void addIdentifyProduct(AssessParam assessParam) {
        ProductEntityAssess assess = new ProductEntityAssess();
        BeanUtils.copyProperties(assessParam,assess);
        assess.setProductEntityAssessTime(new Date());
        assessMapper.insert(assess);
        entityMapper.updateById(new ProductEntity().setProductEntityId(assessParam.getProductEntityId()).setProductEntityStatus("已评估").setAssessManId(assessParam.getAssessManId()));
    }

    @Override
    public IPage<AssessDto> findAssessProduct(PageParam pageParam) {
        Page<AssessDto> assessDtoPage = new Page<>(pageParam.getPageIdx(), pageParam.getPageSize());
        IPage<AssessDto> assessDto = assessMapper.findIdentifyProduct(assessDtoPage,pageParam.getProductEntityId());

        return assessDto;
    }
}
